package com.ambulance.project.biz.controller.vr;

import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.project.biz.dto.pad.TreatDoctorInfo;
import com.ambulance.project.biz.entity.Hospital;
import com.ambulance.project.manager.domain.BizDepart;
import com.ambulance.project.manager.domain.BizDoctor;
import com.ambulance.project.manager.domain.BizHospital;
import com.ambulance.project.manager.domain.HospitalDoctorDto;
import com.ambulance.project.manager.service.IBizDepartService;
import com.ambulance.project.manager.service.IBizDoctorService;
import com.ambulance.project.manager.service.IBizHospitalService;
import com.ambulance.project.manager.utils.DoctorAndNurseCommonUtil;
import com.ambulance.project.manager.utils.PadUserLoginResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/***
 *  @description
 *  @author zhao
 *  @date: 2020/5/14
 *  @version: v1.0
 */
@Api(tags = {"随车医生-会诊列表相关接口"})
@RestController
@RequestMapping(value = "/vr/v1/treat", method = RequestMethod.POST)
public class VrTreatDoctorController {

    @Autowired
    private IBizDepartService iBizDepartService;
    @Autowired
    private IBizDoctorService iBizDoctorService;

    @Autowired
    private DoctorAndNurseCommonUtil doctorAndNurseCommonUtil;
    @Autowired
    private IBizHospitalService iBizHospitalService;


    @RequestMapping(value = "dep/list")
    @ResponseBody
    @ApiOperation(value = "科室列表", notes = "科室列表", produces = "application/json")
    @ApiResponses({
            @ApiResponse(code = 200, response = BizDepart.class, message = "响应")
    })
    public Object depList(
    ) {
        return AjaxResult.success2("操作成功", iBizDepartService.selectBizDepartList());
    }

    @RequestMapping(value = "dep/doctors")
    @ResponseBody
    @ApiOperation(value = "科室医生列表", notes = "科室医生列表", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "科室标识,若不传则查询全部科室医生", paramType = "query", dataType = "String"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = TreatDoctorInfo.class, message = "响应")
    })
    public Object depDoctors(
            @RequestParam(value = "id", required = false) Integer id
    ) {
        BizDoctor bizDoctor = new BizDoctor();
        // todo 查询当前外援的医生列表
        if (null == id) {
            return AjaxResult.success2("操作成功", iBizDoctorService.selectBizDoctorList2(bizDoctor));
        }
        bizDoctor.setDepartId(id);
        return AjaxResult.success2("操作成功", iBizDoctorService.selectBizDoctorList2(bizDoctor));
    }

    @RequestMapping(value = "dep/hospital")
    @ResponseBody
    @ApiOperation(value = "医院列表", notes = "医院列表", produces = "application/json")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = Hospital.class, message = "响应")
    })
    public Object depHospital(
    ) {

        BizHospital bizHospital = new BizHospital();
        PadUserLoginResult padLoginUser = doctorAndNurseCommonUtil.getPadLoginUser();
        bizHospital.setUid(padLoginUser.getUid().longValue());
        bizHospital.setStatus(1L);
        List<BizHospital> bizHospitals = iBizHospitalService.selectBizHospitalList(bizHospital);
        return AjaxResult.success2("操作成功", bizHospitals);
    }


    @RequestMapping(value = "dep/allhospital")
    @ResponseBody
    @ApiOperation(value = "三合一接口", notes = "医院、科室、医生列表", produces = "application/json")
    @ApiImplicitParams({
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = HospitalDoctorDto.class, message = "响应")
    })
    public Object HospitalDoctorDep(
    ) {
        BizHospital bizHospital = new BizHospital();
        PadUserLoginResult padLoginUser = doctorAndNurseCommonUtil.getPadLoginUser();
        bizHospital.setUid(padLoginUser.getUid().longValue());
        bizHospital.setStatus(1L);
        List<BizHospital> bizHospitals = iBizHospitalService.selectBizHospitalList(bizHospital);
        final ArrayList<HospitalDoctorDto> hospitalDoctorDtos = new ArrayList<>();
        for (BizHospital item : bizHospitals
        ) {
            final HospitalDoctorDto hospitalDoctorDto = new HospitalDoctorDto();
            hospitalDoctorDto.setCommonID(item.getHospitalID().toString());
            hospitalDoctorDto.setName(item.getHospitalName());
            hospitalDoctorDto.setDepart(item.getDepart());
            hospitalDoctorDto.setType(item.getType().toString());
            hospitalDoctorDto.setUid(item.getUid().toString());
            hospitalDoctorDtos.add(hospitalDoctorDto);
        }
        final BizDoctor bizDoctor = new BizDoctor();
        bizDoctor.setUid(padLoginUser.getUid().longValue());
        // 医院接口
        final List<TreatDoctorInfo> treatDoctorInfos = iBizDoctorService.selectBizDoctorList2(bizDoctor);
        for (TreatDoctorInfo item : treatDoctorInfos
        ) {
            final HospitalDoctorDto hospitalDoctorDto = new HospitalDoctorDto();
            hospitalDoctorDto.setUid(padLoginUser.getUid().toString());
            hospitalDoctorDto.setType("3");
            hospitalDoctorDto.setDepart(item.getDepart());
            hospitalDoctorDto.setName(item.getName());
            hospitalDoctorDto.setCommonID(item.getDoctorID().toString());
            hospitalDoctorDto.setHospital(item.getHospital());
            hospitalDoctorDtos.add(hospitalDoctorDto);
        }
        return AjaxResult.success2("操作成功", hospitalDoctorDtos);

    }
}
